using Classified.Data.Infrastructure;
using Classified.Data.Repositories;
using Classified.Service;
using Classified.Web.Services;

[assembly: WebActivator.PreApplicationStartMethod(typeof(Classified.Web.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(Classified.Web.App_Start.NinjectWebCommon), "Stop")]

namespace Classified.Web.App_Start
{
    using System;
    using System.Web;

    using Microsoft.Web.Infrastructure.DynamicModuleHelper;

    using Ninject;
    using Ninject.Web.Common;

    public static class NinjectWebCommon
    {
        private static readonly Bootstrapper bootstrapper = new Bootstrapper();

        /// <summary>
        /// Starts the application
        /// </summary>
        public static void Start()
        {
            DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
            DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
            bootstrapper.Initialize(CreateKernel);
        }

        /// <summary>
        /// Stops the application.
        /// </summary>
        public static void Stop()
        {
            bootstrapper.ShutDown();
        }

        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

            RegisterServices(kernel);
            return kernel;
        }

        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            kernel.Bind<IUnitOfWork>().To<UnitOfWork>();
            kernel.Bind<IDatabaseFactory>().To<DatabaseFactory>();
            kernel.Bind<IUserRepository>().To<UserRepository>();
            kernel.Bind<IRoleRepository>().To<RoleRepository>();
            kernel.Bind<ISecurityService>().To<SecurityService>();
            //kernel.Bind<IFormsAuthenticationService>().To<FormsAuthenticationService>();
            kernel.Bind<IClassifiedAdCategoryRepository>().To<ClassifiedAdCategoryRepository>();
            kernel.Bind<IClassifiedRepository>().To<ClassifiedAdRepository>();
            kernel.Bind<ILocationRepository>().To<LocationRepository>();
            kernel.Bind<IClassifiedPictureRepositories>().To<ClassifiedPictureRepositories>();
            kernel.Bind<IClassifiedCommentRepository>().To<ClassifiedCommentRepository>();
            kernel.Bind<IOderDetailRepositories>().To<OderDetailRepositories>();
            kernel.Bind<IOrderTypeRepositories>().To<OrderTypeRepositories>();
            kernel.Bind<ICategoryAttributeRepository>().To<CategoryAttributeRepository>();
            kernel.Bind<IAttributeValueRepository>().To<AttributeValueRepository>();
            kernel.Bind<IClasifiedAttributeRepository>().To<ClasifiedAttributeRepository>();
            kernel.Bind<ICountryRepository>().To<CountryRepository>();
            kernel.Bind<IQueuedEmailRepositories>().To<QueuedEmailRepositories>();
            kernel.Bind<ITopViewRepositories>().To<TopViewRepositories>();
            kernel.Bind<IPageRepositories>().To<PageRepositories>();
            kernel.Bind<ICurrencyRepository>().To<CurrencyRepository>();
            kernel.Bind<IMyAccountRepositories>().To<MyAccountRepositories>();
            kernel.Bind<IEmailVerificationlLogRepositories>().To<EmailVerificationlLogRepositories>();
            kernel.Bind<IMessageInfoRepositories>().To<MessageInfoRepositories>();
        }
    }
}
